//路由守卫功能
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
function useAuth() {
  let navigate = useNavigate();
  let [isLogin, setIsLogin] = useState(false);
  //获取token
  let token = localStorage.getItem("token");
  useEffect(() => {
    if (token) {
      //如果有正常跳转,不做拦截
      setIsLogin(true);
    } else {
      //如果没有token,则跳转登录页
      setIsLogin(false);
      navigate("/login");
    }
  }, []);
  return { isLogin: isLogin };
}

export default useAuth;
